package com.quik.web.token.mapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.quik.backend.mapper.BaseDao;
import com.quik.entity.DtaToken;
import com.quik.entity.DtaTokenType;
import com.quik.entity.TokenTypeBoundProduct;

/**
 * 功能说明：
 *      手牌相关业务逻辑持久化类
 * @author Administrator
 *
 */
@Repository
public class TokenDao extends BaseDao<DtaToken> {
	/**
	 * 根据条件查询手牌类型数量
	 * @param tokenTypeName
	 * @param productName
	 * @param productNo
	 * @return
	 * @throws Exception
	 */
	public int findTokenTypeCount(String tokenTypeName, String productName, String productNo) throws Exception{
		Map map = new HashMap(3);
		map.put("tokenTypeName", tokenTypeName == null ? null : tokenTypeName.trim());
		map.put("productName", productName == null ? null : productName.trim());
		map.put("productNo", productNo == null ? null : productNo.trim());
		
		int count = (Integer)get("findTokenTypeCount", map);
		return count;
	}
	
	/**
	 * 根据条件查询手牌类型列表（分页）
	 * @param tokenTypeName
	 * @param productName
	 * @param productNo
	 * @param page
	 * @param rows
	 * @return
	 * @throws Exception
	 */
	public List findTokenType(String tokenTypeName, String productName, String productNo, 
			Integer intPage, Integer pageSize) throws Exception{
		Map map = new HashMap(5);
		map.put("tokenTypeName", tokenTypeName == null ? null : tokenTypeName.trim());
		map.put("productName", productName == null ? null : productName.trim());
		map.put("productNo", productNo == null ? null : productNo.trim());
		map.put("currPage", (intPage - 1) * pageSize);
		map.put("pageSize", pageSize);
		
		List list = load("findTokenType", map);
		return list;
	}
	
	/**
	 * 根据手牌类型查询手牌数量
	 * @param tokenTypeName
	 * @return
	 * @throws Exception
	 */
	public int findTokenTypeCountByTokenTypeName(String tokenTypeName) throws Exception{
		int count = (Integer)get("findTokenTypeCountByTokenTypeName", (Object)tokenTypeName);
		return count;
	}
	
	/**
	 * 新增手牌类型
	 * @param tokenType
	 * @param bound
	 * @throws Exception
	 */
	public void addTokenType(DtaTokenType tokenType, TokenTypeBoundProduct bound) throws Exception{
		add("addTokenType", tokenType);
		
		DtaTokenType type = (DtaTokenType)get("findTokenTypeByName", (Object)tokenType.getToken_type_name());
		bound.setToken_type_id(type.getId());
		
		add("addTokenTypeBoundProduct", bound);
	}
	
	/**
	 * 根据条件查询手牌数量
	 * @return
	 */
	public int findTokenCount(String tokenNo, String tokenTypeName) throws Exception{
		Map map = new HashMap(2);
		map.put("tokenNo", tokenNo == null ? null : tokenNo.trim());
		map.put("tokenTypeName", tokenTypeName == null ? null : tokenTypeName.trim());
		
		int count = (Integer)get("findTokenCount", map);
		return count;
	}
	
	/**
	 * 根据条件查询手牌列表（分页）
	 * @param tokenNo
	 * @param tokenTypeName
	 * @param page
	 * @param rows
	 * @return
	 * @throws Exception
	 */
	public List findToken(String tokenNo, String tokenTypeName, Integer intPage, Integer pageSize) throws Exception{
		Map map = new HashMap(4);
		map.put("tokenNo", tokenNo == null ? null : tokenNo.trim());
		map.put("tokenTypeName", tokenTypeName == null ? null : tokenTypeName.trim());
		map.put("currPage", (intPage - 1) * pageSize);
		map.put("pageSize", pageSize);
		
		List list = load("findToken", map);
		return list;
	}
	
	/**
	 * 根据手牌编号查询手牌数量
	 * @param tokenNo
	 * @return
	 * @throws Exception
	 */
	public int findTokenCountByTokenNo(String tokenNo) throws Exception{
		int count = (Integer)get("findTokenCountByTokenNo", (Object)tokenNo);
		return count;
	}
	
	/**
	 * 新增手牌
	 * @param token
	 * @throws Exception
	 */
	public void addToken(DtaToken token) throws Exception{
		add("addToken", token);
	}
	
}
